package com.thxy.jxgl.bumen.manager;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.thxy.jxgl.db.DB;
import com.thxy.jxgl.javaBean.BuMen;
import com.thxy.jxgl.javaBean.GangWei;
import com.thxy.jxgl.javaBean.User;
import com.thxy.jxgl.javaBean.khbz;
import com.thxy.jxgl.javaBean.khinfo;
import com.thxy.jxgl.javaBean.khjsff;
import com.thxy.jxgl.javaBean.khmbz;
import com.thxy.jxgl.javaBean.khxm;
import com.thxy.jxgl.javaBean.khzb;



public class BumenManager {

	private static BumenManager instance = new BumenManager();
	
	private BumenManager(){}
	
	public static BumenManager getInstance(){
		return instance;
	}
	
	public List getBumen(){
		List bmlist = new ArrayList();
		Connection conn = null;
		PreparedStatement pstm = null;
		ResultSet rs = null;
		String sql = "select * from t_bumen";		
		try {
			conn = DB.getConn();
			pstm = conn.prepareStatement(sql);
			rs = pstm.executeQuery();
			while (rs.next()) {
				BuMen bm=new BuMen();
				bm.setDeptNo(rs.getString("bm_id"));
				bm.setDeptName(rs.getString("bm_name"));
				bmlist.add(bm);
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}finally{			
			DB.close(rs);			
			DB.close(pstm);
			DB.close(conn);
		}
		return bmlist;		
	}
	public boolean addDept(String deptno,String deptname){
		Connection conn=null;
		PreparedStatement pstm=null;
		String sql="INSERT INTO t_bumen (bm_id,bm_name) VALUES(?,?)";
		try {
			conn = DB.getConn();
			pstm = conn.prepareStatement(sql);
			pstm.setString(1, deptno);
			pstm.setString(2, deptname);
			return pstm.execute();	
		} catch (SQLException e) {
			e.printStackTrace();
			return false;
		}finally{				
			DB.close(pstm);
			DB.close(conn);
		}
	}
	public boolean deleDept(String deptno){
		Connection conn=null;
		PreparedStatement pstm=null;
		String sql="DELETE FROM t_bumen WHERE bm_id=?";
		try {
			conn = DB.getConn();
			pstm = conn.prepareStatement(sql);
			pstm.setString(1, deptno);
			return pstm.execute();	
		} catch (SQLException e) {
			e.printStackTrace();
			return false;
		}finally{				
			DB.close(pstm);
			DB.close(conn);
		}
	}
	
	
		
}
